package com.gw.jpa.controller;

import com.gw.jpa.entity.Course;
import com.gw.jpa.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController //所有方法返回的都是json格式
@RequestMapping("/course") //定义模块名称
public class CourseController {
    @Autowired
    CourseService courseService; //自动注入
    @PostMapping("")
    public Course addCourse(Course course){

        //调用service层添加课程信息
        return courseService.addCourse(course);
    }

    @GetMapping("/{cid}")
    public Course getCourse(@PathVariable("cid") Integer cid){

        //调用service层获取指定cid的课程信息
        return courseService.getCourse(cid);
    }

    @PutMapping("")
    public Course updateCourse(Course course){

        //调用service层更新课程信息
        return courseService.updateCourse(course);
    }

    @GetMapping("")
    public List<Course> courseList(){

        //调用service层获所有的课程信息取
        return courseService.getCourseJquery();
    }

    @DeleteMapping("/{cid}")
    public void deleteCourse(@PathVariable("cid") Integer cid){

        //调用service层删除指定cid的课程信息
        courseService.deleteCourse(cid);
    }
}
